package cn.gzmli.dtt.common.controll;

import cn.gzmli.dtt.common.annotation.Comment;
import cn.gzmli.dtt.common.entity.PageInfo;
import cn.gzmli.dtt.common.entity.Result;
import cn.gzmli.dtt.common.service.UserMacService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 * @Descript 用户Mac接口
 * @Author jiangdw
 * @Date 2020/4/9
 */
@RestController
@RequestMapping("/userMac")
public class UserMacController{

    @Autowired
    private UserMacService userMacService;

    @RequestMapping("/save")
    @Comment("保存用户的mac地址")
    public Result save(
            @NotNull(message = "用户id不能为空")
                Integer userId,

            @NotEmpty(message = "Mac地址不能为空")
            @Size(max = 32, message = "Mac地址最大长度为32")
                String pcMac) throws Exception {
        return userMacService.save(userId, pcMac);
    }

    @RequestMapping("/remove")
    @Comment("删除用户的mac地址")
    public Result remove(
            @NotNull(message = "id不能为空")
                    Integer id) throws Exception {
        return userMacService.removeUserMacById(id);
    }

    @RequestMapping("/query")
    @Comment("查询用户的mac地址")
    public Result query(
            @NotNull(message = "用户id不能为空")
                    Integer userId,
                    PageInfo pageInfo
    ) throws Exception {
        return userMacService.findUserMacByUserId(userId, pageInfo);
    }

    @RequestMapping("/update")
    @Comment("修改用户的mac地址")
    public Result update(
            @NotNull(message = "id不能为空")
                    Integer id,
            @NotNull(message = "用户id不能为空")
                    Integer userId,

            @NotEmpty(message = "Mac地址不能为空")
            @Size(max = 32, message = "Mac地址最大长度为32")
                    String pcMac
    ) throws Exception {
        return userMacService.updateUserMacById(id,userId, pcMac);
    }

}
